<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            height: 100px;

        }
    </style>
</head>

<body>

    <script>
        //封装一个生成随机数的函数
        function random(min, max) {
            return Math.floor(Math.random() * (max - min + 1)) + min
        }
        let r = Math.floor(Math.random() * 256)
        let g = Math.floor(Math.random() * 256)
        let b = Math.floor(Math.random() * 256)
        document.write(`
        <div style=" background-color:rgb(${r},${g},${b});"></div>
        `)

        let arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']
        let newArr = []
        let colour = ''
        for (let i = 0; i < 6; i++) {
            newArr.push(arr[random(0, arr.length - 1)])
        }
        for (let [key, item] of newArr.entries()) {
            colour += item
        }
        document.write(`
        <div style=" background-color:#${colour};"></div>
        `)
    </script>
</body>

</html>